package com.woniu.humanresource.service.impl;

import com.woniu.humanresource.dao.UserDao;
import com.woniu.humanresource.entity.LoginUserDetail;
import com.woniu.humanresource.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    //自动注入密码编码
    @Autowired
    PasswordEncoder passwordEncoder;

    @Autowired
    UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user;
        //方法参数s就是账号  在数据库里查有没有账号
        user = userDao.selectUserByUname(s);
        user.setPermission(userDao.selectPermissionByUname(s));
        return new LoginUserDetail(user);
    }
}
